
package com.work.db.dao;

import java.util.*;

import com.work.db.*;
import com.work.db.entity.*;

public class LeaveDaoImpl extends GenericDaoImpl<LeaveOfAbsence, Long> implements LeaveDao {

	public LeaveDaoImpl(Class<LeaveOfAbsence> type) {
		super(type);
	}

	@Override
	public Integer getRemainingLeave(Employer employer, int year)
	{
		List<NativeQueryParam> params = new ArrayList<NativeQueryParam>();
		params.add(new NativeQueryParam("employerId", employer.getId()));
		params.add(new NativeQueryParam("year", year));

		return findOneByNativeQuery(SqlQuery.GET_REMAINING_LEAVE, params, Integer.class);
	}
	
	@Override
	public List<LeaveOfAbsence> getTakenLeaves(Employer employer, List<LeaveTypeEnum> selectedLeaves)
	{
		List<String> leaves = new ArrayList<String>();
		for (LeaveTypeEnum leaveTypeEnum : selectedLeaves) {
			leaves.add(leaveTypeEnum.toString());
		}
		
		List<NativeQueryParam> params = new ArrayList<NativeQueryParam>();
		params.add(new NativeQueryParam("employerId", employer.getId()));
		params.add(new NativeQueryParam("leaves", leaves, true));

		return findByNativeQuery(SqlQuery.GET_TAKEN_LEAVES, params);
	}
}